﻿namespace ZQNB.Web.Common.Controllers.Api
{
    //[RoutePrefix("Api/Account")]
    //public class AccountController : ApiController
    //{

    //    private readonly IMembershipHelper _membershipHelper;
    //    public AccountController(IMembershipHelper membershipHelper)
    //    {
    //        _membershipHelper = membershipHelper;
    //    }


    //    public class UserInfo
    //    {
    //        public string User { get; set; }
    //        public string Password { get; set; }
    //    }

    //    [HttpPost]
    //    [Route("Authenticate")]
    //    [AllowAnonymous]
    //    public HttpResponseMessage Authenticate([FromBody]UserInfo ui)
    //    {

    //        if (string.IsNullOrEmpty(ui.User) || string.IsNullOrEmpty(ui.Password))
    //        {
    //            return new HttpResponseMessage(HttpStatusCode.BadRequest);
    //        }

    //        var userId = _membershipHelper.GetAccountId(ui.User);
    //        if (userId != null)
    //        {
    //            var mr = _membershipHelper.Validate(userId.Value, ui.Password);
    //            if (mr.Success)
    //            {
    //                //var OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
    //                var identity = new ClaimsIdentity(Startup.OAuthBearerOptions.AuthenticationType);
    //                identity.AddClaim(new Claim(ClaimTypes.Name, ui.User));
    //                //identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userIdentity.Id));

    //                var ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
    //                var currentUtc = new SystemClock().UtcNow;
    //                ticket.Properties.IssuedUtc = currentUtc;
    //                ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromDays(300));
    //                var accessToken = Startup.OAuthBearerOptions.AccessTokenFormat.Protect(ticket);

    //                var response = new HttpResponseMessage(HttpStatusCode.OK)
    //                {
    //                    Content = new StringContent(accessToken, Encoding.UTF8, "application/json")
    //                };
    //                return response;
    //            }
    //        }

    //        return new HttpResponseMessage(HttpStatusCode.BadRequest);
    //    }

    //    [HttpGet]
    //    [Route("ValidateToken")]
    //    public String GetValidateToken()
    //    {
    //        var user = this.User.Identity;
    //        return string.Format("User: {0}", user.GetUserName());
    //    }
    //}
}
